﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Linq;

namespace BulldogCMS.Data.Tests
{
    [TestClass]
    public class TemplateTest
    {
        private BulldogCMS.Data.Templates.ITemplatesProvider CreateWrongXMLProvider()
        {
            XDocument templatesXDoc = XDocument.Load(TestingData.ReflectionHelper.GetResourceStream("BulldogCMS.Data.Tests.TestingData.WrongTemplates.xml"));
            BulldogCMS.Data.Templates.XMLTemplatesProvider xmlTemplatesProvider = new Templates.XMLTemplatesProvider(templatesXDoc);
            return xmlTemplatesProvider;
        }

        private BulldogCMS.Data.Templates.ITemplate CreateWrongTemplate()
        {
            return this.CreateWrongXMLProvider().GetTemplate("Folder");
        }

        [TestMethod]
        public void ThrowsExceptionWhenReferencingMissingUseTemplate()
        {
            var template = this.CreateWrongTemplate();
            try
            {
                var useTemplates = template.UseTemplates.ToList();
                Assert.Fail("TemplateNotFoundException expected");
            }
            catch (Exceptions.TemplateNotFoundException ex)
            {

            }
            catch
            {
                Assert.Fail("Exception thrown, but is not of type TemplateNotFoundException");
            }
        }

        [TestMethod]
        public void ThrowsExceptionWhenReferencingMissingAllowTemplate()
        {
            var template = this.CreateWrongTemplate();
            try
            {
                var useTemplates = template.AllowTemplates.ToList();
                Assert.Fail("TemplateNotFoundException expected");
            }
            catch (Exceptions.TemplateNotFoundException ex)
            {

            }
            catch
            {
                Assert.Fail("Exception thrown, but is not of type TemplateNotFoundException");
            }
        }

    }
}
